/*
 * PossoftNetChess.java
 *
 * Created on 17. �erven 2007, 21:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cz.possoft.client.gui.applet;

import java.awt.Container;

import javax.swing.JApplet;

import layout.TableLayout;
import cz.possoft.client.gui.panel.ChatPanel;
import cz.possoft.client.gui.panel.NastaveniSpodniPanel;
import cz.possoft.client.gui.panel.NastaveniVrchniPanel;
import cz.possoft.client.gui.panel.nastavenispodnipanel.panel.NastaveniShowPanel;
import cz.possoft.client.loader.LoaderHolder;
import cz.possoft.client.threads.DialogThread;
import cz.possoft.client.utils.PanelHolderUtils;
import cz.possoft.messages.PropertiesManager;
import cz.possoft.messages.Text;

/**
 * Hlavni trida cele aplikace. Predstavuje swingovy applet se vsema panelama.
 * 
 * @author mara
 */
public class PossoftNetChess extends JApplet {
    
  // Hlavni herni panel - vlevo nahore.  
  //GamePanel gamePanel;
  
  // Panel s chatem
  ChatPanel chatPanel;
  
  // panel vpravo nahore s nastavenim
  NastaveniVrchniPanel nastaveniVrsekButton;
  // panel vpravo dole s nastavenim detailu
  NastaveniSpodniPanel nastaveniSpodniPanel;
  
  // dialogove vlakno kontroluje stav dialogu
  static DialogThread dialogThread;
    
    /** Creates a new instance of PossoftNetChess */
    public PossoftNetChess() {
    }
    
    // inicializce hlavniho panelu
    public void init() {
        double size[][] =
        {{650,250},
        {350,170,180}};

        Container mainPanel=getContentPane();
        mainPanel.setLayout(new TableLayout(size));
        PanelHolderUtils.setApplet(this);
        
        // Pridavani mensich panelu do hlavniho panelu        
        mainPanel.add(getNastaveniVrsekButton(),"1,0,1,0");        
        mainPanel.add(getChatPanel(),"0,2,0,2");
        mainPanel.add(getNastaveniSpodniPanel(),"1,1,1,2");
        try {
        	// this should deploy all game panels from deploy directory.
        	LoaderHolder.getInstance();
        }
        catch (Exception e) {
        	System.err.println("Exception during initial deployment");
        	e.printStackTrace();
        }
    }
    
    // podle hodnoty gameComboBoxu vytvori novou instanci gamePanelu
    // TODO: add this implementation to some better location
    public void setGamePanelAccordingToComboBox() {
    	String prefix = (String)NastaveniShowPanel.getGamesComboBox().getPrefixForSelectedGame();
    	PanelHolderUtils.setCurrentGamePanelFromPrefix(prefix);               
    }
    
    // vraci spodni panel s chatem
    public ChatPanel getChatPanel() {
        if (chatPanel==null) {
            chatPanel=new ChatPanel();
            }
        return chatPanel;
    }
    
    // vraci panel vpravo nahore
    public NastaveniVrchniPanel getNastaveniVrsekButton() {
        if (nastaveniVrsekButton==null) {
            nastaveniVrsekButton=new NastaveniVrchniPanel();
            }
        return nastaveniVrsekButton;
    }
    
    // vraci panel vpravo dole
    public NastaveniSpodniPanel getNastaveniSpodniPanel() {
        if (nastaveniSpodniPanel==null) {
            nastaveniSpodniPanel=NastaveniSpodniPanel.getNastaveniSpodniPanel();
            }
        return nastaveniSpodniPanel;
    }      
    
    // metoda prida vsechny gamePanels na hlavni panel. Game panely ale maji inicialne nastavenu neviditelnost
    /*private void addAllGamePanels() {
    	for (GamePanel gamePanel : PanelHolderUtils.getAllGamePanels()) {
    		getContentPane().add(gamePanel, "0,0,0,1");
    	}
    }*/
    
  // main boot method
  public static void main(String[] args) {
     ShowApplet.runApplet("cz.possoft.client.gui.applet.PossoftNetChess", 900, 735, PropertiesManager.getInstance().getMessageForKey(Text.NADPIS));
                                        }
}
